#include "trap.h"
   .set mips32
   .set noat
   .globl main
   .text
main:

#SB and LB and LBU
    li $k0, 0x0
    li $s0, 0x8654f3f1
    sb $s0, 0x1($zero)

    li $v0, 0xfffffff1
    li $v1, 0x000000f1

    lb $t0, 0x1($zero)
    lbu $t1, 0x1($zero)

    bne $t0, $v0, FALSE
    bne $t1, $v1, FALSE

#SH and LH and LHU
    li $k0, 0x1
    li $s0, 0x8654f3f1
    sh $s0, 0x10($zero)
    sh $s0, 0x21($zero)

    li $v0, 0xfffff3f1
    li $v1, 0x0000f3f1

    lh $t0, 0x10($zero)
    lhu $t1, 0x10($zero)

    lh $t3, 0x21($zero)
    lhu $t4, 0x21($zero)

    bne $t0, $v0, FALSE
    bne $t1, $v1, FALSE

#SW and LW
    li $k0, 0x2
    li $s0, 0x8654f3f1
    sw $s0, 0x1000($zero)
    sw $s0, 0x3333($zero)

    li $v0, 0x8654f3f1

    lw $t0, 0x1000($zero)

    lw $t1, 0x3333($zero)

    bne $t0, $v0, FALSE
    j   SUCCESS

FALSE:
    HIT_BAD_TRAP
SUCCESS:
    HIT_GOOD_TRAP

    .org 0x380      #04读，05写
        nop
        mfc0 $a0, $13

        andi $a0, $a0, 0x00000ff
        srl $a0, $a0, 0x2

        li $a1, 0x04
        li $a2, 0x05
        beq $a0, $a1, READ_BADADDR
        beq $a0, $a2, WRITE_BADADDR

        HIT_BAD_TRAP

        READ_BADADDR:
            ERET
        WRITE_BADADDR:
            ERET

